<template>
  <div>
    <MesHeader :title="title" icon="el-icon-s-grid" style="padding: 0 10px"></MesHeader>
    <MesTable :tableData="tableData" :columns="columns"></MesTable>
  </div>
</template>

<script setup>
import MesHeader from '@/components/basic/MesHeader'
import MesTable from '@/components/basic/MesTable'
import { getCurrentInstance, ref } from 'vue'

const that = getCurrentInstance().appContext.config.globalProperties
let title = ref('')
let tableData = ref([])
const columns = [
  {
    title: '产品名称',
    field: 'ProductName',
  },
  {
    title: '产品编码',
    field: 'ProductCode',
  },
  {
    title: '规格',
    field: 'Specification',
  },
  {
    title: '数量',
    field: 'Qnty',
  },
  {
    title: '创建人',
    field: 'Creator',
  },
  {
    title: '创建时间',
    field: 'CreateDate',
  },
  {
    title: '修改人',
    field: 'Modifier',
  },
  {
    title: '修改时间',
    field: 'ModifyDate',
  },
]

const getDetailData = async (row, type) => {
  let id = ''
  let sort = ''
  let url = ''
  if (type == '其他入库') {
    id = row.SundriesInsetMain_ID
    sort = 'SundriesInsetDetail_ID'
    url = '/api/Ware_SundriesInsetMain/getDetailPage'
  } else {
    id = row.SundriesOutMain_ID
    sort = 'SundriesOutDetail_ID'
    url = '/api/Ware_SundriesOutMain/getDetailPage'
  }

  const res = await that.http.post(url, {
    order: 'desc',
    page: 1,
    rows: 100,
    sort,
    value: id,
    wheres: '[]',
  })
  if (res.status == 0) {
    // console.log(res.rows);
    tableData.value = res.rows
  }
}

const rowClick = (row, type) => {
  type == '其他入库' ? (title.value = '其他入库-明细') : (title.value = '其他出库-明细')
  getDetailData(row, type)
}

defineExpose({
  rowClick,
})
</script>
